home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11230 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.0 KB  |  76 lines

  1. Path: realtime.net!usenet
  2. From: rflores@bga.com (Roberto Flores)
  3. Newsgroups: comp.lang.c++
  4. Subject: Need Help in using a DLL
  5. Date: 13 Mar 1996 04:57:33 GMT
  6. Organization: Real/Time Communications Internet customer posting
  7. Message-ID: <4i5kjt$bvb@news2.realtime.net>
  8. NNTP-Posting-Host: jake-4m.aip.realtime.net
  9. Mime-Version: 1.0
  10. X-RTcode: 8aa6f45731bd86255d4655df
  11. X-Newsreader: WinVN 0.93.11
  12.  
  13. My background is UNIX/C w/ ESQL. but now I am developing for Windows 
  14. 3.1. I am using MSVC++ 1.5.  I have successfully used a DLL 
  15. (GETENVAR.DLL) in a Powerbuilder application to retrieve values of DOS 
  16. environment variables.  I need to be able to do the same using 'C' ( I do not have
  17. the LIB file).  Attached is the code I am using to do this.  I maybe off base, so 
  18. please help!  I am building a quick working prototype using the MS QuickWin 
  19. option.  The code finds the DLL using the GetProcAddress 
  20. function successfully, but I do not know to use the function. The 
  21. function in the DLL I want to use is:
  22.  
  23.           GetEnvironmentVar("<Environment-Variable>", rtn_string);
  24.  
  25. Code follows:
  26.  
  27.    #include <stdio.h>
  28.    #include <windows.h>
  29.    
  30.    void main ()
  31.    {
  32.     void prtvar(char *text1);
  33.         
  34.         prtvar("USERID");
  35.    }
  36.    
  37.    void prtvar(text1)
  38.    char *text1;
  39.    {                   
  40.       char *rtn_envar;
  41.       char *envar;
  42.       
  43.       HINSTANCE hinstGetEnVar;
  44.       BOOL (FAR *lpfnGetEnvironmentVar);
  45.                      
  46.       sprintf(envar, text1);
  47.       printf("%s: ", envar);
  48.       hinstGetEnVar = LoadLibrary("GETENVAR.DLL");
  49.       
  50.       if ( hinstGetEnVar > HINSTANCE_ERROR ) {
  51.          (FARPROC) lpfnGetEnvironmentVar = GetProcAddress(hinstGetEnVar, 
  52. "GetEnvironmentVar");
  53.          if (lpfnGetEnvironmentVar != NULL ) {
  54.  
  55.        /* I need to use the function here.  */
  56.  
  57.              printf("%s\n", rtn_envar );
  58.          }
  59.          else
  60.             printf("Find Function Failed\n");
  61.       }
  62.       FreeLibrary( hinstGetEnVar );
  63.    }
  64.  
  65. Please help by replying to:
  66.  
  67.         rflores@bga.com  or Robert.Flores@tpwd.state.tx.us
  68.  
  69. Thanks A Bunch!
  70.  
  71. Robert Flores
  72.  
  73.  
  74.  
  75.  
  76.